package com.kou.filter;

import com.kou.pojo.Goods;
import com.kou.pojo.Orders;
import com.kou.service.*;
import com.kou.service.impl.GoodsServiceImpl;
import com.kou.service.impl.GoodsTypeServiceImpl;
import com.kou.service.impl.OrderServiceImpl;
import com.kou.utils.StrUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author SteinY
 * @create 2022-03-25 10:18
 * @description:
 */
@WebFilter({"/admin/showAllOrder.jsp"})
public class OrderFilter implements Filter {
    OrderService orderService = new OrderServiceImpl();
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    //从cookie中获取两周之内的用户信息
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;

        List<Orders> orders = orderService.show();

        UserService userService = new UserServiceImpl();
        for (Orders order : orders) {
            order.setUsername(userService.findUserName(order.getUid()));
        }

       // System.out.println(types.size());
        request.getSession().setAttribute("orderList",orders);
        //放行！！
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}